package com.woniuxy.microsportsserver.sleepmag.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.common.bean.PageDto;
import com.woniuxy.microsportsserver.bean.SleepAnalysisInfo;
import com.woniuxy.microsportsserver.bean.SleepInfo;
import com.woniuxy.microsportsserver.sleepmag.mapper.SleepMapper;
import com.woniuxy.microsportsserver.sleepmag.service.ISleepService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SleepServiceImpl implements ISleepService {
    @Resource
    private SleepMapper sleepMapper;

    @Override
    public PageDto findAll(SleepInfo sleepInfo , Integer pageNum, Integer pageSize)  {
        if(pageNum<=0){
            return null;
        }
        PageHelper.startPage(pageNum, pageSize);
        List<SleepInfo> data = sleepMapper.findAll(sleepInfo);
        PageInfo<SleepInfo> pageInfo = new PageInfo<>(data);

        PageDto pageDto = new PageDto();
        pageDto.setTotal(pageInfo.getTotal());
        pageDto.setData(data);
        return pageDto;
    }
    //近一年深睡浅睡的平均数
    @Override
    public List<SleepAnalysisInfo> findAvgSleepValue() {
        return sleepMapper.findAvgSleepValue();
    }

    @Override
    public List<SleepAnalysisInfo> findSleepPercentage() {
        return sleepMapper.findSleepPercentage();
    }
}
